//////////////////////////////////////////////////////////////////////
//
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
//  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  Globals.h
//
//          Global variable declarations.
//
//////////////////////////////////////////////////////////////////////

#ifndef GLOBALS_H
#define GLOBALS_H

#include <windows.h>
#include <ole2.h>
#include <olectl.h>
#include <assert.h>
#include "msctf.h"

//#define DllExport   __declspec( dllexport )

void DllAddRef();
void DllRelease();

#define IME_ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))

#define TEXTSERVICE_LANGID    MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)

#define TEXTSERVICE_DESC    _TEXT("Sample Text Service")
#define TEXTSERVICE_MODEL   TEXT("Apartment")

#define TEXTSERVICE_ICON_INDEX  101
#define LANGBAR_ITEM_DESC   _TEXT("Sample Text Service Button")

extern HINSTANCE g_hInst;

extern LONG g_cRefDll;

extern CRITICAL_SECTION g_cs;

extern const CLSID c_clsidTextService;

extern const GUID c_guidProfile;
extern const GUID c_guidLangBarItemButton;

//
// GUID for the preserved keys.
//
// {A0194CE7-9551-4661-8849-DD169A0D6164}
static const GUID GUID_PRESERVEDKEY_ONOFF = 
{ 0xa0194ce7, 0x9551, 0x4661, { 0x88, 0x49, 0xdd, 0x16, 0x9a, 0xd, 0x61, 0x64 } };


// {7B82BB11-19BC-4A2E-AFC2-E38C26DC7AC2}
static const GUID GUID_PRESERVEDKEY_F6 = 
{ 0x7b82bb11, 0x19bc, 0x4a2e, { 0xaf, 0xc2, 0xe3, 0x8c, 0x26, 0xdc, 0x7a, 0xc2 } };

//
//  define two guids for display attribute info. This textservice has
//  two display attribute. One is for input text and the other is for the
//  converted text.
//
//      c_guidDisplayAttributeInput 
//      c_guidDisplayAttributeConverted
//
// {33E18BFF-65CB-4BDB-BE6C-7C4C1597B944}
const GUID c_guidDisplayAttributeInput = { 0x33e18bff, 0x65cb, 0x4bdb, { 0xbe, 0x6c, 0x7c, 0x4c, 0x15, 0x97, 0xb9, 0x44 } };

// {F9D0E5C3-9CFD-4484-AC3E-C15EF78889CD}
static const GUID c_guidDisplayAttributeConverted = 
{ 0xf9d0e5c3, 0x9cfd, 0x4484, { 0xac, 0x3e, 0xc1, 0x5e, 0xf7, 0x88, 0x89, 0xcd } };


//
// the preserved keys declaration
//
// VK_KANJI is the virtual key for Kanji key, which is available in 106
// Japanese keyboard.
//
static const TF_PRESERVEDKEY c_pkeyOnOff0 = { 0xC0, TF_MOD_ALT };
static const TF_PRESERVEDKEY c_pkeyOnOff1 = { VK_KANJI, TF_MOD_IGNORE_ALL_MODIFIER };
static const TF_PRESERVEDKEY c_pkeyF6 =   { VK_F6, TF_MOD_ON_KEYUP };

//
// the description for the preserved keys
//
static const TCHAR c_szPKeyOnOff[] = _TEXT("OnOff");
static const TCHAR c_szPKeyF6[]    = _TEXT("Function 6");

HRESULT GetFullCLSIDPath(LPTSTR* clsidPath);
void HandleWin32Error(DWORD dwError);
void InsertTextAtSelection(TfEditCookie ec, ITfContext *pContext, const WCHAR *pchText, ULONG cchText);
BOOL RegisterCategories();
void UnregisterCategories();
//BOOL RegisterProfiles();
HRESULT RegisterProfilesWithProfileManager();
void UnregisterProfiles();
BOOL RegisterServer();
void UnregisterServer();

void FreeGlobalObjects(void);
BOOL IsRangeCovered(TfEditCookie ec, ITfRange *pRangeTest, ITfRange *pRangeCover);


// export functions
STDAPI DllUnregisterServer(void);
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppvObj);
STDAPI DllCanUnloadNow(void);
STDAPI DllRegisterServer(void);

//
// The cookie for the sink to CLangBarItemButton.
//
#define TEXTSERVICE_LANGBARITEMSINK_COOKIE 0x0fab0fab

//
// The ids of the menu item of the language bar button.
//
#define MENUITEM_INDEX_0 0
#define MENUITEM_INDEX_1 1
#define MENUITEM_INDEX_INSERTHELLO 2
#define MENUITEM_INDEX_OPENCLOSE 3
#define CLSID_STRLEN 38  // strlen("{xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}")

//
// The descriptions of the menu item of the language bar button.
//
static TCHAR c_szMenuItemDescription0[] = _TEXT("Menu Item Description 0");
static TCHAR c_szMenuItemDescription1[] = _TEXT("Menu Item Description 1");
static TCHAR c_szMenuItemDescriptionInsertHello[] = _TEXT("Insert Hello");
static TCHAR c_szMenuItemDescriptionOpenClose[] = _TEXT("Open");

static const TCHAR c_szInfoKeyPrefix[] = TEXT("CLSID\\");
static const TCHAR c_szInProcSvr32[] = TEXT("InProcServer32");
static const TCHAR c_szModelName[] = TEXT("ThreadingModel");




#endif // GLOBALS_H
